<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OpenShoe: spi.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenShoe
   &#160;<span id="projectnumber">0.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">spi.h</div>  </div>
</div>
<div class="contents">
<a href="spi_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*This file is prepared for Doxygen automatic documentation generation.*/</span>
<a name="l00018"></a>00018 <span class="comment">/* Copyright (c) 2009 Atmel Corporation. All rights reserved.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00021"></a>00021 <span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<a name="l00022"></a>00022 <span class="comment"> *</span>
<a name="l00023"></a>00023 <span class="comment"> * 1. Redistributions of source code must retain the above copyright notice, this</span>
<a name="l00024"></a>00024 <span class="comment"> * list of conditions and the following disclaimer.</span>
<a name="l00025"></a>00025 <span class="comment"> *</span>
<a name="l00026"></a>00026 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright notice,</span>
<a name="l00027"></a>00027 <span class="comment"> * this list of conditions and the following disclaimer in the documentation</span>
<a name="l00028"></a>00028 <span class="comment"> * and/or other materials provided with the distribution.</span>
<a name="l00029"></a>00029 <span class="comment"> *</span>
<a name="l00030"></a>00030 <span class="comment"> * 3. The name of Atmel may not be used to endorse or promote products derived</span>
<a name="l00031"></a>00031 <span class="comment"> * from this software without specific prior written permission.</span>
<a name="l00032"></a>00032 <span class="comment"> *</span>
<a name="l00033"></a>00033 <span class="comment"> * 4. This software may only be redistributed and used in connection with an Atmel</span>
<a name="l00034"></a>00034 <span class="comment"> * AVR product.</span>
<a name="l00035"></a>00035 <span class="comment"> *</span>
<a name="l00036"></a>00036 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY ATMEL &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED</span>
<a name="l00037"></a>00037 <span class="comment"> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span>
<a name="l00038"></a>00038 <span class="comment"> * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE</span>
<a name="l00039"></a>00039 <span class="comment"> * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR</span>
<a name="l00040"></a>00040 <span class="comment"> * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<a name="l00041"></a>00041 <span class="comment"> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<a name="l00042"></a>00042 <span class="comment"> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<a name="l00043"></a>00043 <span class="comment"> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<a name="l00044"></a>00044 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00045"></a>00045 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE</span>
<a name="l00046"></a>00046 <span class="comment"> *</span>
<a name="l00047"></a>00047 <span class="comment"> */</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="preprocessor">#ifndef _SPI_H_</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#define _SPI_H_</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &quot;<a class="code" href="compiler_8h.html" title="Compiler file for AVR32.">compiler.h</a>&quot;</span>
<a name="l00053"></a>00053 
<a name="l00055"></a><a class="code" href="spi_8h.html#a0131f2774f4e3dd71567400683b60405">00055</a> <span class="preprocessor">#define SPI_TIMEOUT       15000</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00058"></a><a class="code" href="spi_8h.html#a1ec07ad94d5f6276c1c0b41d0550fe52">00058</a> <span class="preprocessor">#define SPI_MODE_0       0</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span>
<a name="l00061"></a><a class="code" href="spi_8h.html#af2af9f45539491c9753960535dc20fde">00061</a> <span class="preprocessor">#define SPI_MODE_1       1</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span>
<a name="l00063"></a>00063 
<a name="l00065"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982">00065</a> <span class="keyword">typedef</span> <span class="keyword">enum</span>
<a name="l00066"></a>00066 {
<a name="l00067"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a826883012efb59b29ee363729ea51bc1">00067</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a826883012efb59b29ee363729ea51bc1">SPI_ERROR</a> = -1,
<a name="l00068"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a2b1fe832bba9b2799c09ddec72f7df75">00068</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a2b1fe832bba9b2799c09ddec72f7df75">SPI_OK</a> = 0,
<a name="l00069"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982aae8d126a5cc88871e124cb6de9d13c20">00069</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982aae8d126a5cc88871e124cb6de9d13c20">SPI_ERROR_TIMEOUT</a> = 1,
<a name="l00070"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a328f03299bad929fb56b83f9053aef74">00070</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a328f03299bad929fb56b83f9053aef74">SPI_ERROR_ARGUMENT</a>,
<a name="l00071"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a01283f9df4cdf6697d23cdb09c4890e8">00071</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a01283f9df4cdf6697d23cdb09c4890e8">SPI_ERROR_OVERRUN</a>,
<a name="l00072"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a185a888047ea2c585fe7472c752723cf">00072</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a185a888047ea2c585fe7472c752723cf">SPI_ERROR_MODE_FAULT</a>,
<a name="l00073"></a><a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a52c5c585a979c4c81d104e7a75b04a1d">00073</a>   <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982a52c5c585a979c4c81d104e7a75b04a1d">SPI_ERROR_OVERRUN_AND_MODE_FAULT</a>
<a name="l00074"></a>00074 } <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a>;
<a name="l00075"></a>00075 
<a name="l00077"></a><a class="code" href="structspi__options__t.html">00077</a> <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00078"></a>00078 {
<a name="l00080"></a><a class="code" href="structspi__options__t.html#a9f89caeb223b8e82f29628a47eb66f9a">00080</a>   uint8_t <a class="code" href="structspi__options__t.html#a9f89caeb223b8e82f29628a47eb66f9a" title="The SPI channel to set up.">reg</a>;
<a name="l00081"></a>00081 
<a name="l00083"></a><a class="code" href="structspi__options__t.html#a397070a4a1f42ac5c8e45538b0cd0163">00083</a>   uint32_t <a class="code" href="structspi__options__t.html#a397070a4a1f42ac5c8e45538b0cd0163" title="Preferred baudrate for the SPI.">baudrate</a>;
<a name="l00084"></a>00084 
<a name="l00086"></a><a class="code" href="structspi__options__t.html#a99da3363b981ddff67b8463f760ac22d">00086</a>   uint8_t <a class="code" href="structspi__options__t.html#a99da3363b981ddff67b8463f760ac22d" title="Number of bits in each character (8 to 16).">bits</a>;
<a name="l00088"></a><a class="code" href="structspi__options__t.html#a86f15a4bd903dc7f46001b017d6396c8">00088</a>   uint8_t <a class="code" href="structspi__options__t.html#a86f15a4bd903dc7f46001b017d6396c8" title="Delay before first clock pulse after selecting slave (in PBA clock periods).">spck_delay</a>;
<a name="l00089"></a>00089 
<a name="l00091"></a><a class="code" href="structspi__options__t.html#aedb727a3304efbedc75f61c3312c6dae">00091</a>   uint8_t <a class="code" href="structspi__options__t.html#aedb727a3304efbedc75f61c3312c6dae" title="Delay between each transfer/character (in PBA clock periods).">trans_delay</a>;
<a name="l00092"></a>00092 
<a name="l00094"></a><a class="code" href="structspi__options__t.html#a9bbd0582cc9fb1f01aaba5761f139119">00094</a>   uint8_t <a class="code" href="structspi__options__t.html#a9bbd0582cc9fb1f01aaba5761f139119" title="Sets this chip to stay active after last transfer to it.">stay_act</a>;
<a name="l00095"></a>00095 
<a name="l00097"></a><a class="code" href="structspi__options__t.html#aeb3e5bbe92bd45feadb8fc3abe2ea402">00097</a>   uint8_t <a class="code" href="structspi__options__t.html#aeb3e5bbe92bd45feadb8fc3abe2ea402" title="Which SPI mode to use when transmitting.">spi_mode</a>;
<a name="l00098"></a>00098 
<a name="l00102"></a><a class="code" href="structspi__options__t.html#a734ad2abb63f00b69a38ef1eb7c68812">00102</a>   uint8_t <a class="code" href="structspi__options__t.html#a734ad2abb63f00b69a38ef1eb7c68812">modfdis</a>;
<a name="l00103"></a>00103 } <a class="code" href="structspi__options__t.html" title="Option structure for SPI channels.">spi_options_t</a>;
<a name="l00104"></a>00104 
<a name="l00110"></a>00110 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_reset(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112         spi-&gt;cr = AVR32_SPI_CR_SWRST_MASK;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 
<a name="l00119"></a>00119 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_master_mode(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121         spi-&gt;MR.mstr = 1;
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123 
<a name="l00128"></a>00128 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_slave_mode(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130         spi-&gt;MR.mstr = 0;
<a name="l00131"></a>00131 }
<a name="l00132"></a>00132 
<a name="l00137"></a>00137 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_enable_modfault(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00138"></a>00138 {
<a name="l00139"></a>00139         spi-&gt;MR.modfdis = 0;
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00146"></a>00146 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_disable_modfault(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00147"></a>00147 {
<a name="l00148"></a>00148         spi-&gt;MR.modfdis = 1;
<a name="l00149"></a>00149 }
<a name="l00150"></a>00150 
<a name="l00155"></a>00155 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_enable_loopback(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157         spi-&gt;MR.llb = 1;
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159 
<a name="l00164"></a>00164 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_disable_loopback(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00165"></a>00165 {
<a name="l00166"></a>00166         spi-&gt;MR.llb = 0;
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168 
<a name="l00173"></a>00173 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_enable_chipselect_decoding(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175         spi-&gt;MR.pcsdec = 1;
<a name="l00176"></a>00176 }
<a name="l00177"></a>00177 
<a name="l00182"></a>00182 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_disable_chipselect_decoding(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184         spi-&gt;MR.pcsdec = 0;
<a name="l00185"></a>00185 }
<a name="l00186"></a>00186 
<a name="l00192"></a>00192 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_chipselect(<span class="keyword">volatile</span> avr32_spi_t *spi,uint8_t chip_select)
<a name="l00193"></a>00193 {
<a name="l00194"></a>00194         spi-&gt;MR.pcs = chip_select;
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196 
<a name="l00201"></a>00201 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_enable_variable_chipselect(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00202"></a>00202 {
<a name="l00203"></a>00203         spi-&gt;MR.ps = 1;
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205 
<a name="l00210"></a>00210 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_disable_variable_chipselect(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212         spi-&gt;MR.ps = 0;
<a name="l00213"></a>00213 }
<a name="l00214"></a>00214 
<a name="l00220"></a>00220 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_delay(<span class="keyword">volatile</span> avr32_spi_t *spi,uint8_t delay)
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222         spi-&gt;MR.dlybcs = delay;
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00232"></a>00232 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_chipselect_delay_bct(<span class="keyword">volatile</span> avr32_spi_t *spi,
<a name="l00233"></a>00233                         uint8_t chip_select, uint8_t delay)
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235   Assert(chip_select&gt;3);
<a name="l00236"></a>00236   <span class="keywordflow">switch</span>(chip_select) {
<a name="l00237"></a>00237     <span class="keywordflow">case</span> 0:
<a name="l00238"></a>00238       spi-&gt;CSR0.dlybct = delay;
<a name="l00239"></a>00239       <span class="keywordflow">break</span>;
<a name="l00240"></a>00240     <span class="keywordflow">case</span> 1:
<a name="l00241"></a>00241       spi-&gt;CSR1.dlybct  = delay;
<a name="l00242"></a>00242       <span class="keywordflow">break</span>;
<a name="l00243"></a>00243     <span class="keywordflow">case</span> 2:
<a name="l00244"></a>00244       spi-&gt;CSR2.dlybct  = delay;
<a name="l00245"></a>00245       <span class="keywordflow">break</span>;
<a name="l00246"></a>00246     <span class="keywordflow">case</span> 3:
<a name="l00247"></a>00247       spi-&gt;CSR3.dlybct  = delay;
<a name="l00248"></a>00248       <span class="keywordflow">break</span>;
<a name="l00249"></a>00249   }
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00258"></a>00258 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_chipselect_delay_bs(<span class="keyword">volatile</span> avr32_spi_t *spi,
<a name="l00259"></a>00259                         uint8_t chip_select, uint8_t delay)
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261   Assert(chip_select&gt;3);
<a name="l00262"></a>00262   <span class="keywordflow">switch</span>(chip_select) {
<a name="l00263"></a>00263     <span class="keywordflow">case</span> 0:
<a name="l00264"></a>00264       spi-&gt;CSR0.dlybs = delay;
<a name="l00265"></a>00265       <span class="keywordflow">break</span>;
<a name="l00266"></a>00266     <span class="keywordflow">case</span> 1:
<a name="l00267"></a>00267       spi-&gt;CSR1.dlybs  = delay;
<a name="l00268"></a>00268       <span class="keywordflow">break</span>;
<a name="l00269"></a>00269     <span class="keywordflow">case</span> 2:
<a name="l00270"></a>00270       spi-&gt;CSR2.dlybs  = delay;
<a name="l00271"></a>00271       <span class="keywordflow">break</span>;
<a name="l00272"></a>00272     <span class="keywordflow">case</span> 3:
<a name="l00273"></a>00273       spi-&gt;CSR3.dlybs  = delay;
<a name="l00274"></a>00274       <span class="keywordflow">break</span>;
<a name="l00275"></a>00275   }
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277 
<a name="l00284"></a>00284 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_bits_per_transfer(<span class="keyword">volatile</span> avr32_spi_t *spi, uint8_t chip_select,
<a name="l00285"></a>00285                         uint8_t len)
<a name="l00286"></a>00286 {
<a name="l00287"></a>00287   Assert((len&gt;8)&amp;&amp;(len&lt;16));
<a name="l00288"></a>00288   <span class="keywordflow">switch</span>(chip_select) {
<a name="l00289"></a>00289     <span class="keywordflow">case</span> 0:
<a name="l00290"></a>00290       spi-&gt;CSR0.bits = len - 8;
<a name="l00291"></a>00291       <span class="keywordflow">break</span>;
<a name="l00292"></a>00292     <span class="keywordflow">case</span> 1:
<a name="l00293"></a>00293       spi-&gt;CSR1.bits  = len - 8;
<a name="l00294"></a>00294       <span class="keywordflow">break</span>;
<a name="l00295"></a>00295     <span class="keywordflow">case</span> 2:
<a name="l00296"></a>00296       spi-&gt;CSR2.bits  = len - 8;
<a name="l00297"></a>00297       <span class="keywordflow">break</span>;
<a name="l00298"></a>00298     <span class="keywordflow">case</span> 3:
<a name="l00299"></a>00299       spi-&gt;CSR3.bits  = len - 8;
<a name="l00300"></a>00300       <span class="keywordflow">break</span>;
<a name="l00301"></a>00301   }
<a name="l00302"></a>00302 }
<a name="l00303"></a>00303 
<a name="l00310"></a>00310 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_baudrate_register(<span class="keyword">volatile</span> avr32_spi_t *spi,uint8_t chip_select,
<a name="l00311"></a>00311                         uint8_t scbr)
<a name="l00312"></a>00312 {
<a name="l00313"></a>00313   <span class="keywordflow">switch</span>(chip_select) {
<a name="l00314"></a>00314     <span class="keywordflow">case</span> 0:
<a name="l00315"></a>00315       spi-&gt;CSR0.scbr = scbr;
<a name="l00316"></a>00316       <span class="keywordflow">break</span>;
<a name="l00317"></a>00317     <span class="keywordflow">case</span> 1:
<a name="l00318"></a>00318       spi-&gt;CSR1.scbr  = scbr;
<a name="l00319"></a>00319       <span class="keywordflow">break</span>;
<a name="l00320"></a>00320     <span class="keywordflow">case</span> 2:
<a name="l00321"></a>00321       spi-&gt;CSR2.scbr  = scbr;
<a name="l00322"></a>00322       <span class="keywordflow">break</span>;
<a name="l00323"></a>00323     <span class="keywordflow">case</span> 3:
<a name="l00324"></a>00324       spi-&gt;CSR3.scbr  = scbr;
<a name="l00325"></a>00325       <span class="keywordflow">break</span>;
<a name="l00326"></a>00326   }
<a name="l00327"></a>00327 }
<a name="l00328"></a>00328 
<a name="l00334"></a>00334 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_enable_active_mode(<span class="keyword">volatile</span> avr32_spi_t *spi,uint8_t chip_select)
<a name="l00335"></a>00335 {
<a name="l00336"></a>00336   <span class="keywordflow">switch</span>(chip_select) {
<a name="l00337"></a>00337     <span class="keywordflow">case</span> 0:
<a name="l00338"></a>00338       spi-&gt;CSR0.csaat = 1;
<a name="l00339"></a>00339       <span class="keywordflow">break</span>;
<a name="l00340"></a>00340     <span class="keywordflow">case</span> 1:
<a name="l00341"></a>00341       spi-&gt;CSR1.csaat  = 1;
<a name="l00342"></a>00342       <span class="keywordflow">break</span>;
<a name="l00343"></a>00343     <span class="keywordflow">case</span> 2:
<a name="l00344"></a>00344       spi-&gt;CSR2.csaat  = 1;
<a name="l00345"></a>00345       <span class="keywordflow">break</span>;
<a name="l00346"></a>00346     <span class="keywordflow">case</span> 3:
<a name="l00347"></a>00347       spi-&gt;CSR3.csaat  = 1;
<a name="l00348"></a>00348       <span class="keywordflow">break</span>;
<a name="l00349"></a>00349   }
<a name="l00350"></a>00350 }
<a name="l00351"></a>00351 
<a name="l00358"></a>00358 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_set_mode(<span class="keyword">volatile</span> avr32_spi_t *spi,uint8_t chip_select,
<a name="l00359"></a>00359                         uint8_t flags)
<a name="l00360"></a>00360 {
<a name="l00361"></a>00361   <span class="keywordflow">switch</span>(chip_select) {
<a name="l00362"></a>00362     <span class="keywordflow">case</span> 0:
<a name="l00363"></a>00363       spi-&gt;CSR0.cpol = flags &gt;&gt; 1;
<a name="l00364"></a>00364       spi-&gt;CSR0.ncpha = (flags &amp; 0x1) ^ 0x1;
<a name="l00365"></a>00365       <span class="keywordflow">break</span>;
<a name="l00366"></a>00366     <span class="keywordflow">case</span> 1:
<a name="l00367"></a>00367       spi-&gt;CSR1.cpol  = flags &gt;&gt; 1;
<a name="l00368"></a>00368       spi-&gt;CSR1.ncpha = (flags &amp; 0x1) ^ 0x1;
<a name="l00369"></a>00369       <span class="keywordflow">break</span>;
<a name="l00370"></a>00370     <span class="keywordflow">case</span> 2:
<a name="l00371"></a>00371       spi-&gt;CSR2.cpol  = flags &gt;&gt; 1;
<a name="l00372"></a>00372       spi-&gt;CSR2.ncpha = (flags &amp; 0x1) ^ 0x1;
<a name="l00373"></a>00373       <span class="keywordflow">break</span>;
<a name="l00374"></a>00374     <span class="keywordflow">case</span> 3:
<a name="l00375"></a>00375       spi-&gt;CSR3.cpol  = flags &gt;&gt; 1;
<a name="l00376"></a>00376       spi-&gt;CSR3.ncpha = (flags &amp; 0x1) ^ 0x1;
<a name="l00377"></a>00377       <span class="keywordflow">break</span>;
<a name="l00378"></a>00378   }
<a name="l00379"></a>00379 }
<a name="l00380"></a>00380 
<a name="l00387"></a>00387 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spi_put(<span class="keyword">volatile</span> avr32_spi_t *spi, uint16_t data)
<a name="l00388"></a>00388 {
<a name="l00389"></a>00389         spi-&gt;tdr = data &lt;&lt; AVR32_SPI_TDR_TD_OFFSET;
<a name="l00390"></a>00390 }
<a name="l00391"></a>00391 
<a name="l00398"></a>00398 <span class="keyword">static</span> <span class="keyword">inline</span> uint16_t spi_get(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00399"></a>00399 {
<a name="l00400"></a>00400         <span class="keywordflow">return</span> (spi-&gt;rdr &gt;&gt; AVR32_SPI_RDR_RD_OFFSET);
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402 
<a name="l00411"></a>00411 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="uc3__spi_2spi__master_8h.html#a7a08995ae2193f27979fdd0613f3f189" title="Checks if all transmissions are complete.">spi_is_tx_empty</a>(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00412"></a>00412 {
<a name="l00413"></a>00413   <span class="keywordflow">return</span> (spi-&gt;sr &amp; AVR32_SPI_SR_TXEMPTY_MASK) != 0;
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415 
<a name="l00424"></a>00424 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="uc3__spi_2spi__master_8h.html#afc0784fc74e3a9c6bbf5de5aa87a413f" title="Checks if all transmissions is ready.">spi_is_tx_ready</a>(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00425"></a>00425 {
<a name="l00426"></a>00426   <span class="keywordflow">return</span> (spi-&gt;sr &amp; AVR32_SPI_SR_TDRE_MASK) != 0;
<a name="l00427"></a>00427 }
<a name="l00428"></a>00428 
<a name="l00435"></a>00435 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="uc3__spi_2spi__master_8h.html#a8ec4bf90b5b8de62f3ce6aae2fdfa752" title="Check if the SPI contains a received character.">spi_is_rx_full</a>(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00436"></a>00436 {
<a name="l00437"></a>00437   <span class="keywordflow">return</span> (spi-&gt;sr &amp; AVR32_SPI_SR_RDRF_MASK) != 0;
<a name="l00438"></a>00438 }
<a name="l00439"></a>00439 
<a name="l00446"></a>00446 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="uc3__spi_2spi__master_8h.html#aa137d54c8ea3799cf6f2b2c710569be6" title="Checks if all reception is ready.">spi_is_rx_ready</a>(<span class="keyword">volatile</span> avr32_spi_t *spi)
<a name="l00447"></a>00447 {
<a name="l00448"></a>00448   <span class="keywordflow">return</span> (spi-&gt;sr &amp; (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) ==
<a name="l00449"></a>00449          (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK);
<a name="l00450"></a>00450 }
<a name="l00451"></a>00451 
<a name="l00456"></a>00456 <span class="keyword">extern</span> <span class="keywordtype">void</span> spi_reset(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00457"></a>00457 
<a name="l00468"></a>00468 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a1fc77d26387ef26a9b5020e4e04b3b2e">spi_initSlave</a>(<span class="keyword">volatile</span> avr32_spi_t *spi,
<a name="l00469"></a>00469                                   uint8_t bits,
<a name="l00470"></a>00470                                   uint8_t spi_mode);
<a name="l00471"></a>00471 
<a name="l00480"></a>00480 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a04a1d45030965c52dc63b205166c61c1" title="Sets up the SPI in a test mode where the transmitter is connected to the receiver (local loopback)...">spi_initTest</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00481"></a>00481 
<a name="l00491"></a>00491 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a93b09f2d5b41fe71291968cd2658cba2" title="Initializes the SPI in master mode.">spi_initMaster</a>(<span class="keyword">volatile</span> avr32_spi_t *spi, <span class="keyword">const</span> <a class="code" href="structspi__options__t.html" title="Option structure for SPI channels.">spi_options_t</a> *options);
<a name="l00492"></a>00492 
<a name="l00502"></a>00502 <span class="keyword">extern</span> int16_t <a class="code" href="spi_8c.html#ac4f834a88c24447093521628ed16a72b" title="Calculates the baudrate divider.">getBaudDiv</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> baudrate, uint32_t pba_hz);
<a name="l00503"></a>00503 
<a name="l00517"></a>00517 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#ad76b44e99966bb6a66b122b44f64b928">spi_selectionMode</a>(<span class="keyword">volatile</span> avr32_spi_t *spi,
<a name="l00518"></a>00518                                       uint8_t variable_ps,
<a name="l00519"></a>00519                                       uint8_t pcs_decode,
<a name="l00520"></a>00520                                       uint8_t delay);
<a name="l00531"></a>00531 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#af9d47e62b6b92aa3d786229c24584ae1" title="Selects slave chip.">spi_selectChip</a>(<span class="keyword">volatile</span> avr32_spi_t *spi, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> chip);
<a name="l00532"></a>00532 
<a name="l00546"></a>00546 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a6c7f9eff8ca5319ae5b998255d925a6a" title="Unselects slave chip.">spi_unselectChip</a>(<span class="keyword">volatile</span> avr32_spi_t *spi, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> chip);
<a name="l00547"></a>00547 
<a name="l00564"></a>00564 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a5487ca1d63a13d055c803a6c96067a6f" title="Sets options for a specific slave chip.">spi_setupChipReg</a>(<span class="keyword">volatile</span> avr32_spi_t *spi,
<a name="l00565"></a>00565                                      <span class="keyword">const</span> <a class="code" href="structspi__options__t.html" title="Option structure for SPI channels.">spi_options_t</a> *options,
<a name="l00566"></a>00566                                      uint32_t pba_hz);
<a name="l00571"></a>00571 <span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="spi_8c.html#ac93e5990e8abc811f4ba2fb65e10e94d" title="Enables the SPI.">spi_enable</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00572"></a>00572 
<a name="l00581"></a>00581 <span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="spi_8c.html#a5cc4ac60e6ecf3cdc442265aaa0a63e0" title="Disables the SPI.">spi_disable</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00582"></a>00582 
<a name="l00589"></a>00589 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="spi_8c.html#aa945d35a658c234e2cb650a53dcdaa37" title="Tests if the SPI is enabled.">spi_is_enabled</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00590"></a>00590 
<a name="l00599"></a>00599 <span class="keyword">extern</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="spi_8c.html#a4e0840fa276e1e4bfe182769d458f9d6" title="Checks if there is no data in the transmit register.">spi_writeRegisterEmptyCheck</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00600"></a>00600 
<a name="l00619"></a>00619 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#ab5b92c3f2168e3b0a28f6325efcad5f3" title="Writes one data word in master fixed peripheral select mode or in slave mode.">spi_write</a>(<span class="keyword">volatile</span> avr32_spi_t *spi, uint16_t data);
<a name="l00620"></a>00620 
<a name="l00644"></a>00644 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a7b54e1dd21fe488aeca4a28322df36ff" title="Selects a slave in master variable peripheral select mode and writes one data word to it...">spi_variableSlaveWrite</a>(<span class="keyword">volatile</span> avr32_spi_t *spi,
<a name="l00645"></a>00645                                            uint16_t data,
<a name="l00646"></a>00646                                            uint8_t pcs,
<a name="l00647"></a>00647                                            uint8_t lastxfer);
<a name="l00648"></a>00648 
<a name="l00657"></a>00657 <span class="keyword">extern</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="spi_8c.html#a3675facf1bb501f769ce8e9a3c2fc23f" title="Checks if all transmissions are complete.">spi_writeEndCheck</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00658"></a>00658 
<a name="l00667"></a>00667 <span class="keyword">extern</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="spi_8c.html#a86f2b56ec7eeb0712ef0c5f43e9ae604" title="Checks if there is data in the receive register.">spi_readRegisterFullCheck</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00668"></a>00668 
<a name="l00683"></a>00683 <span class="keyword">extern</span> <a class="code" href="spi_8h.html#a856ecadf3d7fe18c4fc3ae56500f8982" title="Status codes used by the SPI driver.">spi_status_t</a> <a class="code" href="spi_8c.html#a37b77c1847803528025bd60897cc18e8">spi_read</a>(<span class="keyword">volatile</span> avr32_spi_t *spi, uint16_t *data);
<a name="l00684"></a>00684 
<a name="l00696"></a>00696 <span class="keyword">extern</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="spi_8c.html#a354beb51d8e5e95665c089832f3a8631" title="Gets status information from the SPI.">spi_getStatus</a>(<span class="keyword">volatile</span> avr32_spi_t *spi);
<a name="l00697"></a>00697 
<a name="l00698"></a>00698 <span class="preprocessor">#endif  // _SPI_H_</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Mon Dec 19 2011 21:04:51 for OpenShoe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
